package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.mapper.OrderSettingMapper;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <h3>health94_pareant</h3>
 * <p></p>
 *
 * @author : hhw
 * @date : 2020-03-25 10:04
 **/
@Service(interfaceClass = OrderSettingService.class)
public class OrderSettingServiceImpl implements OrderSettingService {

    @Autowired
    private OrderSettingMapper orderSettingMapper;

    @Override
    public void importOrderSettings(ArrayList<OrderSetting> orderSettings) {

        for (OrderSetting orderSetting : orderSettings) {
            //首先验证数据库中是否有该日期的预约数量
            int count = orderSettingMapper.queryOrderSetting(orderSetting);
            if (count != 0 ) {
                //执行修改操作
                orderSettingMapper.updateOrderSetting(orderSetting);
            } else {
                orderSettingMapper.importOrderSetting(orderSetting);
            }
        }
    }

    @Override
    public List<Map<String, String>> queryAllOrderSetting(String date) {
        return orderSettingMapper.queryAllOrderSetting(date);
    }

    @Override
    public void edit(OrderSetting orderSetting) {

        //首先验证数据库中是否有该日期的预约数量
        int count = orderSettingMapper.queryOrderSetting(orderSetting);
        if (count != 0 ) {
            //执行修改操作
            orderSettingMapper.updateOrderSetting(orderSetting);
        } else {
            orderSettingMapper.importOrderSetting(orderSetting);
        }



    }
}
